package com.biostime.qdingding.modules.qd.promotions;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 打折动作链
 * @author phil
 * @version 2015-11-20
 */
public class DiscountChain {
	
	private static Map<String,Discountor> defaultDiscounter = Maps.newHashMap();
	
	private List<Discountor> discountors = Lists.newArrayList();
	
	static{
		defaultDiscounter.put(MemberDiscountor.Formula, new MemberDiscountor());//折扣
		defaultDiscounter.put(FirstNDiscountor.Formula,new FirstNDiscountor());//返利
	}
	
	public void discount(Discountable discountable){
		for(Discountor discountor : discountors){
			discountor.discount(discountable);
		}
	}
	
	public void addDiscountor(String formula){
		if(defaultDiscounter.containsKey(formula)){
			discountors.add(defaultDiscounter.get(formula));
		}
	}

	public void clear() {
		discountors.clear();
	}
}
